﻿using Common;

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Uninstaller
{
    class Program
    {
        static string installiniFile = "install.ini";
        static void Main(string[] args)
        {
            bool silent = false;
            if (args.Length > 0)
            {
                if (args.Contains("-silent")) silent = true;
            }
            #region 读取安装配置
            MyConfiguration opt = new MyConfiguration(false);
            opt.Load(installiniFile);
            string targetFolder = opt.ReadString("TargetFolder");
            string programGroup = opt.ReadString("ProgramGroup");
            string desktopShortcut = opt.ReadString("DesktopShortcut");
            #endregion
            bool comfirm = true;
            if(!silent)
            {
                Console.WriteLine("反安装会清除软件的所有文件，包括你放在软件目录下的文件。");
                Console.WriteLine("确认要继续吗？(Y/N)");
                var n = Console.ReadKey();
                comfirm = n.KeyChar != 'Y' || n.KeyChar != 'y';
            }
            if(comfirm)
            {
                if (File.Exists(desktopShortcut)) File.Delete(desktopShortcut);
                if (Directory.Exists(programGroup)) Directory.Delete(programGroup, true);
                if (Directory.Exists(targetFolder)) Directory.Delete(targetFolder, true);
                Console.WriteLine("程序已经被卸载！任意键结束");
                Console.ReadKey();
            }
            
        }
       

    }
}
